package com.hntest.service.impl;

import com.hntest.dao.CompanyBankInfoDao;
import com.hntest.entity.CompanyBankInfo;
import com.hntest.entity.Pager;
import com.hntest.service.CompanyBankInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("companyBankInfoService")
public class CompanyBankInfoServiceImpl implements CompanyBankInfoService {

    @Autowired
    private CompanyBankInfoDao companyBankInfoDao;

    public void setCompanyBankInfoDao(CompanyBankInfoDao companyBankInfoDao) {
        this.companyBankInfoDao = companyBankInfoDao;
    }

    @Override
    public List<CompanyBankInfo> getListByPage(Pager pager, CompanyBankInfo companyBankInfo) {
        //查询总数量
        pager.setTotalCounts(companyBankInfoDao.getCounts(companyBankInfo));
        //将值存入map中
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("companyBankInfo", companyBankInfo);
        map.put("pageStart", (pager.getCurrPage() - 1) * pager.getPageSize() + 1);
        map.put("pageEnd", pager.getCurrPage() * pager.getPageSize());
        //将map中带回的数据保存到list集合中返回
        List<CompanyBankInfo> list = companyBankInfoDao.getListByPage(map);
        return list;
    }

    @Override
    public List<CompanyBankInfo> getAllBankName() {
        return companyBankInfoDao.getAllBankName();
    }

    @Override
    public int insert(CompanyBankInfo companyBankInfo) {
        return companyBankInfoDao.insert(companyBankInfo);
    }

    @Override
    public CompanyBankInfo getCompanyBankInfoById(int cbiid) {
        return companyBankInfoDao.getCompanyBankInfoById(cbiid);
    }

    @Override
    public int update(CompanyBankInfo companyBankInfo) {
        return companyBankInfoDao.update(companyBankInfo);
    }
}
